﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace project_soft.BLStub
{
   public class Worker1 :Employee1
    {
        DBStubLayer.workerDAC1 wo;
        public Worker1() { 
            wo = new DBStubLayer.workerDAC1(); 
        }

        public Worker1(string User_Name, string User_Password, string User_Address, double User_Phone, double User_Ssn, double User_Salary) {
            Worker1.User_Name1 = User_Name;
            this.User_Password1 = User_Password;
            this.User_Type1 = 2;
            this.User_Address1 = User_Address;
            this.User_Phone1 = User_Phone;
            this.User_Ssn1 = User_Ssn;
            this.User_Salary1 = User_Salary;
            wo = new DBStubLayer.workerDAC1();
        }
        public bool AddProduct(BLStub.Product1 product)
        {
            if (product == null ||product.Product_Name1 == null|| !product.Check_Product_Name(product.Product_Name1) || product.Product_Name1 == ""  )
                return false;
             if (product.Sales_Price1 <= 0 || product.Sales_Price1 <= product.Oraginal_Price1)
               return false;
             if (product.Oraginal_Price1 < 0)
                return false;
             if (product.Avalible_Quantity1 < product.Critcal_Quantity1 || product.Avalible_Quantity1 <= 0)
                return false;
             if (product.Critcal_Quantity1 <= 0)
                return false;
            else 
              return wo.AddProduct(product);
        }
        public bool Update_Product_AfterSalling(BL.Product product) {
            if (product.Update_Product_After_Salling(product)) return true;
            else return false;
        }

        public bool Sell_Products(BLStub.Order1 order) {
            
                if (order ==null||order.Product1==null||order.Quantity==null|| order.Bill==null ||order.Product1.Count == 0 || order.Quantity.Count == 0)
                {
                    return false;
                }
                else
                {
                    if (order.Bill.Insert_Bill(order.Bill))
                    {
                        if (order.Bill.return_Bill_Id(order.Bill))
                        {
                            if (order.Insert_Product_Sell(order, order.Bill.Sales_Id1))
                            {

                                return true;
                            }
                            else
                            {
                                return false;
                            }

                        }
                        else
                        {
                            return false;
                        }
                    }
                    else
                    {
                        return false;
                    }
                    
                }
            }
        }
    }

